// pages/guide/guide.js
import {Request} from '../../utils/request.js';
import mock from '../../utils/mock.js';
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // showLogin: false,

    category: [],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.postData();
  },

  postLottery: function() {
    wx.showModal({
      title: '提示',
      content: '该功能暂不开源',
    })
    return ;
    wx.navigateTo({
      url: '/pages/lottery/post/post',
    })

  },


  onGo: function(e) {
    var that = this;
    
    var index = e.currentTarget.dataset.index;
    var cIndex = e.currentTarget.dataset.cindex;
    var nav = that.data.category[cIndex].nav[index];
    if(nav.type == 'othermin') {
      wx.navigateToMiniProgram({
          appId: nav.appid,
          path: nav.url,
          extraData: {
          },
          // envVersion: ,
          success(res) {
          // 打开成功
          },
          fail: function() {
            wx.showToast({
              title: '参数错误',
              icon: 'none'
            })
          }
      })
    }else if(nav.type == 'mini') {
      wx.navigateTo({
        url: nav.url,
        fail: function() {
          wx.switchTab({
            url: nav.url,
            fail: function() {
              wx.showToast({
                title: '参数错误',
                icon: 'none'
              })
            }
          })
        }
      })
    }else if(nav.type == 'web') {
      wx.navigateTo({
        url: "/pages/web/web?url=" + nav.url,
      })
    }

  
  },

  getUserProfile: function (e) {
    let that = this;

    app.getUserInfo(e, function(res) {
      
    })

  }, 

  postData() {
    var that = this;
    that.setData({
      category: mock.nav
    });

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return app.shareAppMessage();
  }
})